#include<bits/stdc++.h>
#define int long long
#define N 1000005
using namespace std;
int n,k;
int a[N];
int d[N],o[N];
int ans;
int len;
pair<int,int> c[N];
vector<int> g[N];
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-f;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
signed main(){
    freopen("lost.in","r",stdin);
    freopen("lost.out","w",stdout);
    n=read();k=read();
    for(int i=1;i<=n;i++) a[i]=read();
    if(a[1]!=1) ans++;
    for(int i=2;i<=n;i++) g[a[i]].push_back(i);
    for(int i=2;i<=n;i++) d[i]=1e9;
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i:g[x]){
            if(d[i]==1e9){
                d[i]=d[x]+1;
                q.push(i);
            }
        }
    }
    for(int i=1;i<=n;i++) c[i]={d[i],i};
    sort(c+1,c+n+1);
    for(int i=n;i>=1;i--){
        int id=c[i].second;
        if(d[id]<=k&&!o[id]) continue;
        if(o[id]==k-1) ans++;
        else o[a[id]]=max(o[a[id]],o[id]+1);
    }
    printf("%lld",ans);
    return 0;
}